package cn.hnu.qq.client.panel;

import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

import cn.hnu.qq.entity.User;

import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class UserInfoPanel extends JPanel {

	private JLabel account;
	private JLabel sex;
	private JLabel email;
	private JLabel nickName;
	
	/**
	 * Create the panel.
	 */
	@Override
	protected void paintComponent(Graphics g) {
		Image image = null;
		try {
			image = ImageIO.read(new File("src/main/java/image/02.jpg"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		};
				
		g.drawImage(image, 0, 0, this.getWidth(), this.getHeight(), this);

	}
	public UserInfoPanel() {
		setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				FormFactory.DEFAULT_COLSPEC,
				FormFactory.RELATED_GAP_COLSPEC,
				ColumnSpec.decode("default:grow"),},
			new RowSpec[] {
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC,
				FormFactory.DEFAULT_ROWSPEC,}));
		
		JLabel lblAccount = new JLabel("account:");
		add(lblAccount, "4, 2");
		
		account = new JLabel("");
		add(account, "8, 2");
		
		JLabel lblNickName = new JLabel("nick name:");
		add(lblNickName, "4, 4");
		
		nickName = new JLabel("");
		add(nickName, "8, 4");
		
		JLabel lblSex = new JLabel("sex");
		add(lblSex, "4, 6");
		
		sex = new JLabel("");
		add(sex, "8, 6");
		
		JLabel lblEmail = new JLabel("email");
		add(lblEmail, "4, 8");
		
		email = new JLabel("");
		add(email, "8, 8");
	}

	public String getAccount() {
		return account.getText();
	}

	public void setAccount(String account) {
		this.account.setText(account);
	}

	public boolean getSex() {
		return sex.getText().equals("男")?true:false;
	}

	public void setSex(boolean sex) {
		this.sex.setText(sex?"男":"女");
	}

	public String getEmail() {
		return email.getText();
	}

	public void setEmail(String email) {
		this.email.setText(email);
	}

	public String getNickName() {
		return nickName.getText();
	}

	public void setNickName(String nickName) {
		this.nickName.setText(nickName);
	}

	public void setUser(User user) {
		setAccount((user.getAcount()));
		setSex(user.getSex());
		setEmail(user.getEmail());
		setNickName(user.getNickName());
		this.validate();
	}

	
}
